﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SMS
{
    public class StudentsSystem
    {
        private UIManager UIManager;
        private List<Student> Students;
        public StudentsSystem()
        {
            UIManager = new UIManager(this);
            Students = new List<Student>();
        }
        public void Start()
        {
            UIManager.LoginView();
        }

        public bool CheckAccountPassword(string account, string password)
        {
            if (account == "111111" && password == "bb")
            {
                return true;
            }
            return false;
        }

        public List<Student> GetStudents(E_GradeType grade)
        {
            List<Student> ret = new List<Student>();
            for (int i = 0; i < Students.Count; i++)
            {
                if (grade == Students[i].Grade)
                    ret.Add(Students[i]);
            }
            return ret;
        }

        public List<Student> GetStudents(int cla)
        {
            List<Student> ret = new List<Student>();
            for (int i = 0; i < Students.Count; i++)
            {
                if (cla == Students[i].Class)
                    ret.Add(Students[i]);
            }
            return ret;
        }

        public void AddStudent(Student s)
        {
            if (IsHaveStudent(s))
            {
                Student temp = GetStudent(s.ID);
                temp = s;
            }
            else
                Students.Add(s);

        }

        public Student GetStudent(int id)
        {
            for (int i = 0; i < Students.Count; i++)
            {
                if (id == Students[i].ID)
                    return Students[i];
            }
            return null;
        }


        public void RemoveStuden(int id)
        {
            for (int i = 0; i < Students.Count; i++)
            {
                if (id == Students[i].ID)
                {
                    Students.RemoveAt(i);
                    return;
                }
            }
        }

        public bool IsHaveStudent(Student s)
        {
            return IsHaveStudent(s.ID);
        }

        public bool IsHaveStudent(int id)
        {
            for (int i = 0; i < Students.Count; i++)
            {
                if (id == Students[i].ID)
                    return true;
            }
            return false;
        }
    }
}
